
var CURRENT_ACTION = webPath+"/module/home/HomePageAction.do";
var CURRENT_MODULE = 1;//是点击哪个模块触发登录的
/**
 * 初始化按钮事件
 * @memberOf {TypeName} 
 */
function initBtn(){
	$(".system_btn").click(function(){				
		if($(".menu_area").is(":visible")){					
			$(".menu_area").hide();
			$('body').removeClass('menu_bg');
			$(this).removeClass('system_btn_hide').addClass('system_btn_show');
		}else{					
			$(".menu_area").show();
			$('body').addClass('menu_bg');
			$(this).removeClass('system_btn_show').addClass('system_btn_hide');
		}				
	});
		   
  	$('.menu_area_btn').hover(
      function(){
        $(this).find('.menu_link_name').show();
        $(this).find(".menu_link").show().animate({opacity:'show',width:165},400,function(){
           
        });       
      },
      function (){
          $(this).find('.menu_link_name').hide();
          $(this).find(".menu_link").stop().animate({width:60},400,function(){
          	$(this).css({display:"none"});  
      });
               
    });
  	
  	isLookDbBackAuthority();
}

//退出系统
function f_logout4(logFlag){
 var openStatus="left=1000,top=1000,width=10,height=10,resizable=no,menubar=no scrollbar=no";
     if(logFlag=="logout"){
         if(window.confirm("您确实要退出系统吗?")){
        	 reloadFlag=1;
         	 window.location.href=webPath+"/logout.jsp?flag="+logFlag;
              //window.open("logout.jsp?flag="+logFlag,"",openStatus);
         }
     }
     if(logFlag=="close"){
         if(window.confirm("您确实要关闭窗口吗?")){
             window.location.href=webPath+"/logout.jsp?flag="+logFlag;
         }
     }    
 }
 //修改密码
 function f_changePassword(){
    var loginName="<%=loginName%>";
	if(loginName==""){
		top.zDragTool.alert({text:"您的登录信息有误，请重新输入！"});
		return;
	}
	var tmpUrl=webPath+"/modifypswbyuser.jsp?loginName="+loginName+"&haveLogin=1";
	tmpUrl=encodeURI(encodeURI(tmpUrl));

	var myLeft = (window.screen.width-300)/2;
	var myTop= (window.screen.height-300)/2;
	window.open(tmpUrl,'','width=350,height=215,left='+myLeft+',top='+myTop);
}
//打开子系统
function openChildSys(childSysResId,childSysIsXtpzpt, childSysUrl){
	reloadFlag=1;
	writeSysLog(childSysResId);
	window.location.href=webPath+"/index.jsp?childSysResId="+childSysResId+"&childSysIsXtpzpt="+childSysIsXtpzpt+"&childSysUrl="+childSysUrl;
}
//打开子系统
function openKjksh(url,childSysResId){
	//var url = "http://192.168.1.30/fsdads/index?u=xxxx&p=aaa";
	//top.zDragTool.window({url:url,showType:"fullScreen",showButton:false});
	
	writeSysLog(childSysResId);
	window.open(url);
}

//打开3.5平台，断点登录
function openAuth35(url, method, userName, pwd){
	//jumpFlag,传递是否馆藏跳转的参数
	post(url+"/loginAction.action",{method:method,j_username:userName,j_password:pwd,jumpFlag:"1"}, "_blank");
}

//镇海数字报 单点登录
function openZhszb(url, method, userName, pwd){
	//jumpFlag,传递是否馆藏跳转的参数
	post(url,{method:method,j_username:userName,j_password:pwd,jumpFlag:"1"}, "_blank");
}


//打开电子阅览室系统断点登录
function openReadingRoom(url, method, userName, pwd){
	//jumpFlag,传递是否馆藏跳转的参数
	post(url+"//LoginAction.do",{method:method,loginName:userName,userPass:pwd,jumpFlag:"1"}, "_blank");
}

//用此方式提交打开
function post(URL, PARAMS, target) {
	if(!target)target="_self";
    var temp = document.createElement("form");        
    temp.action = URL;
    temp.target = target;
    temp.method = "post";        
    temp.style.display = "none";        
    for (var x in PARAMS) {        
        var opt = document.createElement("textarea");        
        opt.name = x;        
        opt.value = PARAMS[x];        
        temp.appendChild(opt);        
    }        
    document.body.appendChild(temp);        
    temp.submit();        
    return temp;        
}  

//记录登录日志
function writeSysLog(childSysResId){
	/*$.ajax({
   		type: "POST",
   		url: webPath+"/LoginAction.do",
   		data: "method=childLogin&childSysResId="+childSysResId,
   		success: function(data){
   		}	
	});*/
}

function wireUpEvents() {
	var leave_message = '确定要离开当前系统吗?';
	function close(e) {
		if(reloadFlag==0){
			if (!e)
				e = window.event;
			e.cancelBubble = true;
			e.returnValue = leave_message;
			if (e.stopPropagation) {
				e.stopPropagation();
				e.preventDefault();
			}
			return leave_message;
		}
	}
	window.onbeforeunload = close;
	window.onunload=function(){
		if(reloadFlag==0){
			$.ajax({
				async : false,
				url:webPath+'/LoginAction.do?method=logout'
			});
		}
	};
}
//wireUpEvents();
/**
 * 首页菜单栏
 * @param {Object} type
 */
function menuJump(n){
	n = parseInt(n);
	var url = "";
	var status = true;
	switch(n){
		case 1://平台首页
			if(isLogin){url = webPath+"/index/loginAfter-index.jsp";}else{url = webPath+"/index/loginBefore-index.jsp";}
			break;
		case 2://通知公告  1060
			if(isLogin){url = CURRENT_ACTION+"?method=seeAllData&state=1&menuId=1060&forward=allList&pageSize="+top.ITool.pageSize;}else{status = false;}
			break;
	  	case 3://信息共享  1030
			if(isLogin){url = CURRENT_ACTION+"?method=seeAllData&state=1&menuId=1030&forward=allList&pageSize="+top.ITool.pageSize;}else{status = false;}
			break;
	  	case 4://全宗介绍
			//if(isLogin){url=webPath+"/index/dataCenter.jsp";}else{status = false;}
			if(isLogin){url = CURRENT_ACTION+"?method=seeQzData&state=1&forward=qzList&pageSize="+top.ITool.pageSize;}else{status = false;}
			break;
	  	case 5://图片中心
			if(isLogin){url=CURRENT_ACTION+"?method=seeAllImgData&code="+top.ITool.IMG_CODE+"&forward=allImgList&pageSize="+top.ITool.pageSizeImg;}else{status = false;}
			break;
	  	case 6://常用下载  1130
			if(isLogin){url = CURRENT_ACTION+"?method=seeAllData&state=1&menuId=1130&forward=allList&pageSize="+top.ITool.pageSize;}else{status = false;}
			break;
	  	case 7://常见问题 1040
			if(isLogin){url = CURRENT_ACTION+"?method=seeAllData&state=1&menuId=1040&forward=allList&pageSize="+top.ITool.pageSize;}else{status = false;}
			break;
	  	case 8://视频发布 1050
			if(isLogin){url = CURRENT_ACTION+"?method=seeAllData&state=1&menuId=1050&forward=allList&pageSize="+top.ITool.pageSize;}else{status = false;}
			break;
	  	case 9://政策法规 1110
			if(isLogin){url = CURRENT_ACTION+"?method=seeAllData&state=1&menuId=1110&forward=allList&pageSize="+top.ITool.pageSize;}else{status = false;}
			break;
	  	case 10://档案文化 1120
			if(isLogin){url = CURRENT_ACTION+"?method=seeAllData&state=1&menuId=1120&forward=allList&pageSize="+top.ITool.pageSize;}else{status = false;}
			break;
	  	case 11://档案馆介绍  1140
			if(isLogin){url = CURRENT_ACTION+"?method=seeAllData&state=1&menuId=1140&forward=allList&pageSize="+top.ITool.pageSize;}else{status = false;}
			break;
	  	case 12://资料介绍  1150
			if(isLogin){url = CURRENT_ACTION+"?method=seeAllData&state=1&menuId=1150&forward=allList&pageSize="+top.ITool.pageSize;}else{status = false;}
			break;
	}
	if(status){
		$("#iframeid").attr("src",url);
	}else {
		CURRENT_MODULE=n;
		showLogin();
	}
	
}



/******************未登录前Start************************/

/**
 * 初始化登录框
 */
function initLoginDiv(){
	$(".login").click(function(){
		CURRENT_MODULE=1;
		showLogin();
	});
	$(".login_btn,.qx_denglu").click(function(){
		CURRENT_MODULE=1;
		$(".shade").css("display","none");
	});
	$('.chklist').hcheckbox();
	$('#chkitems').click(function(){
		if($('#chkitems').hasClass('checked')){
			  $('.chkitems').addClass('checked');
		}else{
			$('.chkitems').removeClass('checked');
		}
	});
}
/**
 * 显示登录窗口
 */
function showLogin(){
	getCookieStatus();
	$(".shade").css("display","block");
	$("html").css("overflow","hidden");
	$("body").css("overflow","hidden");
	$("#loginName").focus();
	if($("#loginName").val()){
		$("#loginName").val($("#loginName").val());
	}
	
	promptCook.createPrompt({cookName:promptCook.loginPrompt,inputId:"loginName"});
}

/**
 * 回车键执行登录
 */
function enterkey(){
	if($("#promatDiv").css("display") == "none"){
		if($(".shade").css("display") != "none"){
			if(event.keyCode==13){
				f_login();
			}
		}
	}else {
		$("#loginName").val($("#promatSelect").val());
		promptCook.hidePrompt();
		$("#userPass").focus();
	}
}

/**
 * 登录方法
 * @return {TypeName} 
 */
function f_login(){		
	if(!checkform(document.forms[0])){	
		return false;
	}
	saveCookieStatus();
	document.forms[0].submit();
}
/**
 * 重置
 */
function f_empty(){
	document.forms[0].loginName.value="";
	document.forms[0].userPass.value="";
}
function AddToFavorite(){
	//收藏本页地址
	var subUrl='<%="http://" + request.getServerName() + ":"+ request.getServerPort() + request.getContextPath()%>';
	window.external.AddFavorite(subUrl + "/index.jsp" ,'数字档案馆V2.0—馆藏资源管理系统'); 
}
function modifyPwd(){
	window.open('module/user/modifyPass.jsp','new','width=350,height=200,left=250,top=200,scrollbars=no');
}
/**
 * 验证
 * @param {Object} frm
 * @return {TypeName} 
 */
function checkform(frm){
	if (frm.loginName.value==""){
    	top.zDragTool.alert({text:"请先输入用户名！",runMethod:function(){showLogin();frm.loginName.focus();}});
    	
    	return false;
	}
	if (frm.userPass.value==""){
  		top.zDragTool.alert({text:"请输入密码！",runMethod:function(){showLogin();frm.userPass.focus();}});
  		frm.userPass.focus();
  		return false;
	}
	return true;
}
	
function f_enter(){
	if (event.keyCode==13){
		checkform(window.document.forms[0]);
	}
}

function setCookie(cookieInfo){//保存值到cookie中	
	var Days = 30;
	var exp = new Date(); 
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	if(cookieInfo.currentModule != "NO"){
		document.cookie='currentModule='+escape (cookieInfo.currentModule)+";path=/;expires=" + exp.toGMTString();
	}
	if(cookieInfo.loginNameCookie != "NO"){
		document.cookie='loginNameCookie='+escape(cookieInfo.loginNameCookie)+";path=/;expires=" + exp.toGMTString();
	}
	if(cookieInfo.userPassCookie != "NO"){
		document.cookie='userPassCookie='+escape(cookieInfo.userPassCookie)+";path=/;expires=" + exp.toGMTString();
	}
	
} 
function getCookieVal (offset) { //取得项名称为offset的cookie值  
    var endstr = document.cookie.indexOf (";", offset);    
    if (endstr == -1)  
        endstr = document.cookie.length;    
        return unescape(document.cookie.substring(offset, endstr));  
}
function getCookie(name){//根据名字取得cookie中的值
 	var arg = name + "=";    
    var alen = arg.length;    
    var clen = document.cookie.length;    
    var i = 0;    
    while (i < clen) {      
    	var j = i + alen;      
    	if (document.cookie.substring(i, j) == arg){return (getCookieVal (j));}      
        i = document.cookie.indexOf(" ", i) + 1;      
        if (i == 0) break;     
    }    
    return ;  
}
function getCookieStatus(){
	var currentModule=getCookie('currentModule');
	var loginNameCookie=getCookie('loginNameCookie');
	var userPassCookie=getCookie('userPassCookie');
	if(loginNameCookie){
		$("#loginName").val(loginNameCookie);
		$("#rln").attr("checked",true);
		$('#checkboxName').addClass('checked');
	}else {
		$("#rln").removeAttr("checked");
		$('#checkboxName').removeClass('checked');
	}
	if(userPassCookie){
		$("#userPass").val(userPassCookie);
		$("#rpw").attr("checked",true);
		$('#checkboxPassword').addClass('checked');
	}else {
		$("#rpw").removeAttr("checked");
		$('#checkboxPassword').removeClass('checked');
	}
}
function saveCookieStatus(){
	var loginName="";	
	var userPass="";
	 if($("#rln").is(':checked')){
		 loginName = $("#loginName").val();
	 }
	 if($("#rpw").is(':checked')){
		 userPass = $("#userPass").val();
	 }
	var cookieInfo={"loginNameCookie":loginName,"userPassCookie":userPass,"currentModule":CURRENT_MODULE};	
	setCookie(cookieInfo);
}

/******************未登录前End************************/


/**
 * 查看详细  通知公告、制度规范、常用下载
 * @param {Object} id
 */
function seeDetailed(id,parent){
	var url = top.CURRENT_ACTION+"?method=seeDetailed&id="+id+"&forward=seeDetailed";
		zDragTool.window({
			//height:$(window).height()*80/100,
			//width:$(window).width()*80/100,
			url:url,
			title:"查看详细"
	});
}

/**
 * 全宗信息查看
 * @param {Object} id
 */
function seeQzDetailed(id,parent){
	var url = top.CURRENT_ACTION+"?method=seeQzDetailed&id="+id+"&forward=seeQzDetailed";
		zDragTool.window({
			url:url,
			title:"查看详细"
	});
}

/**
 * 首页查看图片详细
 * @param {Object} id
 */
function seeImgDetailed(id){
	var url = CURRENT_ACTION+"?method=seeAllImgData&code="+ITool.IMG_CODE+"&forward=seeImgDetailed&currentId="+id+"&pageSize=6&openType=qt";
	top.zDragTool.window({url:url,showButton:false,showType:"fullScreen"});
}

/**
 * 判断是否有权限查看数据库备份信息并判断备份正常或异常显示一同的图片
 */
function isLookDbBackAuthority(){
	/*var url = CURRENT_ACTION+"?method=isLookDbBackAuthority&lookStatus=0&status=0";
	var success = function(msg){
		if(msg == "1"){//有权限查看并有备份异常
			$("#db_back").css("display","inline");
			$("#db_back").attr("src","images/y.gif");
		}else if(msg == "0"){//有权限查看并备份正常
			$("#db_back").attr("src","images/w.png");
			$("#db_back").css("display","inline");
		}
	}
	getAjax({url:url,success:success})();*/
}

function db_over(){
	$("#db_back").width(20);
	$("#db_back").height(20);
}
function db_out(){
	$("#db_back").width(18);
	$("#db_back").height(18);
}

/**
 * 查看数据库备份信息
 */
function seeDbBackMsg(){
	var url = webPath+"/index/dbMessage.jsp";
	var method = function(){
		window.location.reload();
	}
	top.zDragTool.window({url:url,showButton:false,width:600,title:"数据库备份信息",CancelEvent:isLookDbBackAuthority});
}


